package com.thb.pay.agent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.Lists;
import com.thb.pay.agent.entity.AgentAgentpayPassage;
import com.thb.pay.agent.mapper.AgentAgentpayPassageMapper;
import com.thb.pay.agent.service.AgentAgentpayPassageService;
import com.thb.pay.api.agent.vo.req.AgentAgentpayPassagePageReq;
import com.thb.pay.api.agent.vo.resp.AgentAgentpayPassageVo;
import com.thb.pay.core.utils.PageResult;
import com.thb.pay.db.service.impl.BaseServiceImpl;
import com.thb.pay.db.utils.PageResultUtils;
import com.thb.pay.db.utils.PageUtils;
import com.thb.pay.db.utils.QueryUtils;
import com.xiaoleilu.hutool.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 代理商-代付通道表 服务实现类
 * </p>
 *
 * @author lucky
 * @since 2019-07-21
 */
@Slf4j
@Service
public class AgentAgentpayPassageServiceImpl extends BaseServiceImpl<AgentAgentpayPassageMapper, AgentAgentpayPassage> implements AgentAgentpayPassageService {
    @Override
    public PageResult<AgentAgentpayPassageVo> findPage(AgentAgentpayPassagePageReq pageReq) {
        IPage<AgentAgentpayPassage> currentPage = PageUtils.buildPage(pageReq);
        QueryWrapper wrapper = QueryUtils.buildQueryPage(pageReq);
        IPage<AgentAgentpayPassage> pageResult = super.page(currentPage, wrapper);
        return PageResultUtils.build(pageResult, AgentAgentpayPassageVo.class);
    }

    @Override
    public AgentAgentpayPassageVo getById(Long id) {
        AgentAgentpayPassage resResult = super.selectById(id);
        if (resResult != null) {
            AgentAgentpayPassageVo targetResult = new AgentAgentpayPassageVo();
            BeanUtils.copyProperties(resResult, targetResult);
        }
        return null;
    }

    @Override
    public AgentAgentpayPassageVo getByAgentIdAndPassageId(Long agentId, Integer passageId) {
        LambdaQueryWrapper<AgentAgentpayPassage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AgentAgentpayPassage::getAgentId, agentId);
        queryWrapper.eq(AgentAgentpayPassage::getAgentpayPassageId, passageId);
        List<AgentAgentpayPassage> resResultList = super.selectList(queryWrapper);
        if (CollUtil.isNotEmpty(resResultList)) {
            AgentAgentpayPassage targetResult = new AgentAgentpayPassage();
            BeanUtils.copyProperties(resResultList.get(0), targetResult);
        }
        return null;
    }

    @Override
    public List<AgentAgentpayPassageVo> findAllByAgentId(Long agentId) {
        List<AgentAgentpayPassageVo> targetResultList = Lists.newArrayList();
        LambdaQueryWrapper<AgentAgentpayPassage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AgentAgentpayPassage::getAgentId, agentId);
        List<AgentAgentpayPassage> resResultList = super.selectList(queryWrapper);
        if (CollUtil.isNotEmpty(resResultList)) {
            resResultList.forEach(agentAgentpayPassage -> {
                AgentAgentpayPassageVo targetResult = new AgentAgentpayPassageVo();
                BeanUtils.copyProperties(targetResult, targetResult);
                targetResultList.add(targetResult);

            });
        }
        return targetResultList;
    }
}
